package com.wry.wry_test.algorithm;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * @Author: wangrongyi
 * @Date: 2024/11/25 10:07
 * @Description:
 */
public class Day14 {

    public static int solution(int n, int[] nums) {
        // write code here
        TreeSet<Integer> set = new TreeSet<>((o1, o2) -> o2 - o1);

        for (int num : nums) {
            set.add(num);
        }
        if (set.size() < 3) {
            return set.first();
        } else {
            int index = 0;
            for (Integer i : set) {
                index++;
                if (index == 3) {
                    return i;
                }
            }
        }
        return 0;
    }

    public static void main(String[] args) {
        System.out.println(solution(3, new int[]{3, 2, 1}) == 1);
        System.out.println(solution(2, new int[]{1, 2}) == 2);
        System.out.println(solution(4, new int[]{2, 2, 3, 1}) == 1);
    }
}
